package com.example.hp.controller;

import com.example.hp.entity.Instructors;
import com.example.hp.service.InstructorsService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Instructors)表控制层
 *
 * @author makejava
 * @since 2024-12-15 16:49:38
 */
@RestController
@RequestMapping("instructors")
@Tag(name = "InstructorsController", description = "机构信息管理接口22001010907 许皓翔")
public class InstructorsController {
    /**
     * 服务对象
     */
    @Resource
    private InstructorsService instructorsService;

    /**
     * 分页查询
     *
     * @param instructors 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<Instructors>> queryByPage(@RequestBody Instructors instructors, @RequestParam PageRequest pageRequest) {
        return ResponseEntity.ok(this.instructorsService.queryByPage(instructors, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Instructors> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.instructorsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param instructors 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Instructors> add(Instructors instructors) {
        return ResponseEntity.ok(this.instructorsService.insert(instructors));
    }

    /**
     * 编辑数据
     *
     * @param instructors 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Instructors> edit(Instructors instructors) {
        return ResponseEntity.ok(this.instructorsService.update(instructors));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.instructorsService.deleteById(id));
    }

}

